package panel;


import gui.FrameConnectionWeights;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import types.TMLPNode;
import java.util.ArrayList;
import libs.GenericLib;
import types.TNeuralNetworkStructure;
import libs.Utils;

public class PanelNetworkSimulation extends PanelMy {
	private static final long serialVersionUID = 1L;
	private TNeuralNetworkStructure nn=new TNeuralNetworkStructure();
	private int updateInputLayer=0;
	private ArrayList<TMLPNode> inputWeightedNodes;	
	private ArrayList<TMLPNode> hiddenWeightedNodes;	
	public ArrayList<TMLPNode> activeInputNodes;	
	public ArrayList<TMLPNode> activeHiddenNodes;	
	public float[][] connWeightsInput; //input ve 1.hidden arasindaki connection weightler
	public float[][] connWeightsOutput;//hidden ve output rasindaki connection weightler
	private Image img;
	private boolean isPressedX=true;
	private boolean isNodePressed=false;
	private int posX=0;
	private int posY=0;
	public boolean isRankingFeatures=false;
	
	int top=20;
	int inputLayerPX=150;
	int inputLayerPY=top;
	int inputLayerNodeGap=30;
	int inputLayerNodeWidth=20;
	int nodeWidth=20;
	int firstHiddenPX=400;
	int firstHiddenPY=top;
	int firstHiddenGap=30;
	int secondHiddenPX=400;
	int secondHiddenPY=top;
	int secondHiddenGap=30;
	int outputPX=620;
	int outputPY=top;
	int outputGap=30;	

	
	public PanelNetworkSimulation() {
		init();
//		this.add(getPanel_featureHistogramMatrix(), null);
	}
	
//	private PanelMy panel_featureHistogramMatrix = null;
//	
//	private PanelMy getPanel_featureHistogramMatrix() {
//		if (panel_featureHistogramMatrix == null) {
//			panel_featureHistogramMatrix = new PanelMy();
//			panel_featureHistogramMatrix.setLayout(new GridBagLayout());
//			panel_featureHistogramMatrix.setBounds(new Rectangle(485, 290, 231, 231));
//		}
//		return panel_featureHistogramMatrix;
//	}

	
	private void init() {
		this.addMouseListener(new java.awt.event.MouseAdapter() {   
			public void mousePressed(java.awt.event.MouseEvent e) {
//				isPressed=!isPressed;
				if (isPressedX) {
					posX=e.getX();
					posY=e.getY();
					selectedInputNode=-1;
					selectedHiddenNode=-1;
//					if (frm!=null) frm.setVisible(false);
					for (int i = 0; i < nn.inputSize; i++) {
						isNodePressed=false;
						if (	posX>inputLayerPX	&& 
								posX<inputLayerPX+inputLayerNodeWidth && 
								posY>inputLayerPY+inputLayerNodeGap*i && 
								posY<inputLayerPY+inputLayerNodeGap*i+inputLayerNodeWidth) {
							selectedInputNode=i;
							isNodePressed=true;
							break;
						}
						if (	posX>firstHiddenPX	&& 
								posX<firstHiddenPX+inputLayerNodeWidth && 
								posY>firstHiddenPY+firstHiddenGap*i && 
								posY<firstHiddenPY+firstHiddenGap*i+inputLayerNodeWidth) {
							selectedHiddenNode=i;
							isNodePressed=true;
							break;
						}						
					}
				}
				updateUI();
				//System.out.println("Mouse pressed:(x,y) "+e.getX()+":"+e.getY());
			}
			public void mouseReleased(java.awt.event.MouseEvent e) {    
//				System.out.println("Mouse released:(x,y) "+e.getX()+":"+e.getY());
			}
		});
	}

	
	public void paint(Graphics g)
	{		
		g.setColor(Color.yellow);
		g.fillRect(0, 0, getWidth(), getHeight());
		if (inputWeightedNodes==null) {
			return;
		}
		//b. input ile hidden arasindaki connectionlarin cizgileri renklendirilerek ciziliyor
		float maxInputConn=getMaxConnection(connWeightsInput);
		float minInputConn=getMinConnection(connWeightsInput);
		double deltaInputConn=Math.abs(maxInputConn-minInputConn);
		double IC=255.0/deltaInputConn;
		Color colIC=null;
		
		//b. hidden ile output arasindaki connectionlarin cizgileri renklendirilerek ciziliyor
		float maxOutputConn=getMaxConnection(connWeightsOutput);
		float minOutputConn=getMinConnection(connWeightsOutput);
		double deltaOutputConn=Math.abs(maxOutputConn-minOutputConn);
		double OC=255.0/deltaOutputConn;
		Color colOC=null;
		
//		input ile hidden arasindaki connection weightler biiznillah ciziliyor
		if (isNodePressed && selectedInputNode!=-1) {
			int q=activeInputNodes.get(selectedInputNode).pos;
			for (int j = 0; j < nn.hiddenLayer[0]; j++) {
				try {
					int c=255-Math.abs(Math.round((float)(IC*(Math.abs(connWeightsInput[j][q])-minInputConn))));
					colIC=new Color(c,c,c);
					g.setColor(colIC);
					g.drawLine(
							inputLayerPX+nodeWidth,
							inputLayerPY+nodeWidth/2+inputLayerNodeGap*selectedInputNode,
							firstHiddenPX, 
							firstHiddenPY+nodeWidth/2+firstHiddenGap*j);
				} catch (Exception e) {
					// TODO: handle exception
					g.setColor(Color.LIGHT_GRAY);
				}
			}
			for (int i = 0; i < nn.hiddenLayer[0]; i++) {
				for (int j = 0; j < nn.outputSize; j++) {
					try {
						int c=255-Math.abs(Math.round((float)(OC*(Math.abs(connWeightsOutput[j][i])-minOutputConn))));
						colOC=new Color(c,c,c);
						g.setColor(colOC);
					} catch (Exception e) {
						// TODO: handle exception
						g.setColor(Color.LIGHT_GRAY);
					}
					g.drawLine(firstHiddenPX+nodeWidth,firstHiddenPY+nodeWidth/2+firstHiddenGap*i,outputPX, outputPY+nodeWidth/2+outputGap*j);
				}
			}	
		}
//		b. hidden ile output arasindaki connectionlar cizgileri renklendirilerek ciziliyor
		else if (isNodePressed && selectedHiddenNode!=-1) {			
			try {
				int c=255-Math.abs(Math.round((float)(OC*(Math.abs(connWeightsOutput[0][selectedHiddenNode])-minOutputConn))));
				colOC=new Color(c,c,c);
				g.setColor(colOC);
				g.drawLine(
						firstHiddenPX+nodeWidth,
						firstHiddenPY+nodeWidth/2+firstHiddenGap*selectedHiddenNode,
						outputPX, 
						outputPY+nodeWidth/2);
//				buraya kafa yormak lazim
				for (int i = 0; i < nn.inputSize; i++) {
					int q=activeInputNodes.get(i).pos;
					int j=selectedHiddenNode;
					try {
						c=255-Math.abs(Math.round((float)(IC*(Math.abs(connWeightsInput[j][q])-minInputConn))));
						colIC=new Color(c,c,c);
						g.setColor(colIC);
						g.drawLine(
								inputLayerPX+nodeWidth,
								inputLayerPY+nodeWidth/2+inputLayerNodeGap*i,
								firstHiddenPX, 
								firstHiddenPY+nodeWidth/2+firstHiddenGap*j);
					} catch (Exception e) {
						// TODO: handle exception
						g.setColor(Color.LIGHT_GRAY);
					}
				}
				
			} catch (Exception e) {
				// TODO: handle exception
				g.setColor(Color.LIGHT_GRAY);
			}
		}
//		tum connection weightler b. ciziliyor
		else{
			if (activeInputNodes!=null && activeInputNodes.size()>0) {
				for (int i = 0; i < nn.inputSize; i++) {
					int q=activeInputNodes.get(i).pos;
					for (int j = 0; j < nn.hiddenLayer[0]; j++) {
						try {
							int c=255-Math.abs(Math.round((float)(IC*(Math.abs(connWeightsInput[j][q])-minInputConn))));
							colIC=new Color(c,c,c);
							g.setColor(colIC);
							g.drawLine(
									inputLayerPX+nodeWidth,
									inputLayerPY+nodeWidth/2+inputLayerNodeGap*i,
									firstHiddenPX, 
									firstHiddenPY+nodeWidth/2+firstHiddenGap*j);
						} catch (Exception e) {
							// TODO: handle exception
							g.setColor(Color.LIGHT_GRAY);
						}
					}
				}
				for (int i = 0; i < nn.hiddenLayer[0]; i++) {
					for (int j = 0; j < nn.outputSize; j++) {
						try {
							int c=255-Math.abs(Math.round((float)(OC*(Math.abs(connWeightsOutput[j][i])-minOutputConn))));
							colOC=new Color(c,c,c);
							g.setColor(colOC);
						} catch (Exception e) {
							// TODO: handle exception
							g.setColor(Color.LIGHT_GRAY);
						}
						g.drawLine(firstHiddenPX+nodeWidth,firstHiddenPY+nodeWidth/2+firstHiddenGap*i,outputPX, outputPY+nodeWidth/2+outputGap*j);
					}
				}	
			}
		}
		g.setColor(Color.blue);
		
//		if (updateInputLayer==0) {
//			//b. input layer ciziliyor
//			for (int i = 0; i < nn.inputSize; i++) {
//				g.drawOval(inputLayerPX, inputLayerPY+inputLayerNodeGap*i, inputLayerNodeWidth,inputLayerNodeWidth);
//			}
//		}else{
//		b. input layer nodelari ciziliyor	
		if (activeInputNodes!=null && activeInputNodes.size()>0) {
				g.setColor(Color.blue);
	    		double max=getMaxWeight(activeInputNodes);
	    		double min=getMinWeight(activeInputNodes);
	    		double delta=Math.abs(max-min);
	    		double k=255.0/delta;
	    		Color cl=null;
	    		
				for (int i = 0; i < nn.inputSize; i++) {
	    			try {
	        			int c=Math.abs(255-Math.abs(Math.round((float)(k*(activeInputNodes.get(i).totalWeight-min)))));
	        			cl=new Color(c,c,c);
	        			g.setColor(cl);
	        			int q=activeInputNodes.get(i).pos;
	    				float weight=inputWeightedNodes.get(q).totalWeight;
	    				g.setColor(Color.red);
	    				g.drawString(Utils.formatFloat(weight)+"", inputLayerPX-130, inputLayerPY+15+inputLayerNodeGap*i);
	    				g.setColor(Color.blue);
	    				g.drawString(activeInputNodes.get(i).classLabel+"", inputLayerPX-80, inputLayerPY+15+inputLayerNodeGap*i);
	        			g.setColor(cl);
	    				g.fillOval(inputLayerPX, inputLayerPY+inputLayerNodeGap*i, inputLayerNodeWidth,inputLayerNodeWidth);
	    				g.setColor(Color.green);
	    				g.drawOval(inputLayerPX, inputLayerPY+inputLayerNodeGap*i, inputLayerNodeWidth,inputLayerNodeWidth);
	    				g.setColor(Color.red);
	    				g.drawString(q+"", inputLayerPX+3, inputLayerPY+15+inputLayerNodeGap*i);
					} catch (Exception e) {
//						println(i+".node cizilemedi sebeb:");
//						e.printStackTrace();
						g.setColor(Color.LIGHT_GRAY);
					}
				}
				
			}
			
//		}
		g.setColor(Color.blue);
		//b. 1.hidden layer ciziliyor
		for (int i = 0; i < nn.hiddenLayer[0]; i++) {
			try {
				int c=Math.abs(255-Math.abs(Math.round((float)(OC*(connWeightsOutput[0][i]-minOutputConn)))));
				colOC=new Color(c,c,c);
				g.setColor(colOC);
			} catch (Exception e) {
				// TODO: handle exception
				g.setColor(Color.LIGHT_GRAY);
			}
			g.fillOval(firstHiddenPX, firstHiddenPY+firstHiddenGap*i, nodeWidth,nodeWidth);
			g.setColor(Color.blue);
			g.drawOval(firstHiddenPX, firstHiddenPY+firstHiddenGap*i, nodeWidth,nodeWidth);
			g.setColor(Color.red);
			g.drawString((i+1)+"", firstHiddenPX+3, firstHiddenPY+15+firstHiddenGap*i);
		}
		//b. 2.hidden layer ciziliyor
//		for (int i = 0; i < nn.hiddenLayer[1]; i++) {
//			g.drawOval(secondHiddenPX, secondHiddenPY+secondHiddenGap*i, nodeWidth,nodeWidth);
//		}
		//b. output node ciziliyor
		for (int i = 0; i < nn.outputSize; i++) {
			g.setColor(Color.LIGHT_GRAY);
			g.fillOval(outputPX, outputPY+outputGap*i, nodeWidth,nodeWidth);
			g.setColor(Color.blue);
			g.drawOval(outputPX, outputPY+outputGap*i, nodeWidth,nodeWidth);
		}
		g.setColor(Color.red);
		if (isNodePressed && selectedInputNode!=-1) {
			int q=activeInputNodes.get(selectedInputNode).pos;	    			
			drawInfoBox("input",q,this.getWidth()-200,posY,connWeightsInput,connWeightsOutput,g);
		}
		if (isNodePressed && selectedHiddenNode!=-1) {
			int q=activeHiddenNodes.get(selectedHiddenNode).pos;	    			
			drawInfoBox("hidden",q,this.getWidth()-200,posY,connWeightsInput,connWeightsOutput,g);
		}
		
		int w=this.getWidth();
		int h=this.getHeight();
		g.drawRect(0,0,w-1,h-1);
		g.drawRect(1,1,w-3,h-3);
//		panel_featureHistogramMatrix.updateUI();
	}

	private double getMinWeight(ArrayList<TMLPNode> list) {
		double min=list.get(0).totalWeight;
		for (int i = 0; i < list.size(); i++) {
			if (min>list.get(i).totalWeight) {
				min=list.get(i).totalWeight;
			}
		}
		return min;
	}

	private double getMaxWeight(ArrayList<TMLPNode> list) {
		double max=list.get(0).totalWeight;
		for (int i = 0; i < list.size(); i++) {
			if (max<list.get(i).totalWeight) {
				max=list.get(i).totalWeight;
			}
		}
		return max;
	}

	private int selectedInputNode=-1;
	private int selectedHiddenNode=-1;
	
	public static FrameConnectionWeights frm=null;
	
	private void drawInfoBox(String type,int i, int x, int y, float[][] weight_inputHidden,float[][] weight_hiddenOutput, Graphics g) {
		if (frm==null) {
			frm=new FrameConnectionWeights();
		}
		frm.getLeft().setText("Input-Hidden\n");
		frm.getRight().setText("Hidden-Output\n");
		frm.getProduct().setText("Product\n");
		float toplam=0;
		float absToplam=0;
		float prToplam=0;
		if (type.equals("input")) {
			frm.getLeft().append(i+".node is selected\n");
			frm.getLeft().append("---------------------------\n");
			frm.getRight().append(weight_hiddenOutput[0].length+" hidden nodes\n");
			frm.getRight().append("--------------------------\n");
			frm.getProduct().append("--------\n");
			frm.getProduct().append("--------\n");
			float w1,w2,w3;
			for (int j = 0; j < weight_inputHidden.length; j++) {
				w1=Utils.formatFloat(weight_inputHidden[j][i]);
				frm.getLeft().append((j+1)+". weight : "+w1+"\n");
				toplam+=w1;
				
				w2=Utils.formatFloat(weight_hiddenOutput[0][j]);
				frm.getRight().append((j+1)+". weight : "+w2+"\n");
				
				w3=Math.abs(weight_inputHidden[j][i]*weight_hiddenOutput[0][j]);
				frm.getProduct().append(Utils.formatFloat(w3)+"\n");
				prToplam+=w3;
			}
			absToplam=Math.abs(toplam);
			frm.getLeft().append("---------------------------\nTotal:"+toplam+"\n");
			frm.getLeft().append("Abs.Total:"+absToplam);
			
			frm.getProduct().append("--------\nAbs.Total:\n"+Utils.formatFloat(prToplam)+"\n");
		}
		if (type.equals("hidden")) {
			frm.getLeft().append((i+1)+".node is selected\n");
			frm.getLeft().append("---------------------------\n");
			frm.getRight().append(weight_hiddenOutput.length+" hidden node\n");
			frm.getRight().append("--------------------------\n");
			float w2=Utils.formatFloat(weight_hiddenOutput[0][i]);
			frm.getRight().append((i+1)+". weight : "+w2+"\n");
			float w1;
			for (int j = 0; j < weight_inputHidden[0].length; j++) {
				w1=Utils.formatFloat(weight_inputHidden[i][j]);
				frm.getLeft().append((j+1)+". weight : "+w1+"\n");
				toplam+=w1;				
			}
			absToplam=Math.abs(toplam);
			frm.getLeft().append("---------------------------\nTotal:"+toplam+"\n");
			frm.getLeft().append("Abs.Total:"+absToplam);
			
		}
		
		
		frm.setVisible(true);
		
		
		
		
		
		
		
		
		
		
//		silme
//		int rowH=20;
//		int w=200;
//		int h=(weight_inputHidden.length+3)*rowH;
//		g.setColor(Color.black);
//		g.fillRect(x+3, y+3, w, h);
//		g.setColor(Color.green);
//		float toplam=0;
//		float absToplam=0;
//		g.drawString(i+".node", 10+x, 20+y);
//		for (int j = 0; j < weight_inputHidden.length; j++) {
//			g.drawString((j+1)+".conn. weight :  "+Utils.formatFloat(weight_inputHidden[j][i]), 10+x,40+y+j*rowH);
//			toplam+=weight_inputHidden[j][i];
//			absToplam+=Math.abs(weight_inputHidden[j][i]);
//		}
//		g.drawString("Total :  "+Utils.formatFloat(toplam), 10+x,40+y+weight_inputHidden.length*rowH);
//		g.drawString("Abs Total :  "+Utils.formatFloat(absToplam), 10+x,60+y+weight_inputHidden.length*rowH);
//		
//		g.setColor(Color.red);
//		g.drawRect(x+3, y+3, w, h);
	}

	private float getMinConnection(float[][] d) {
		try {
			float min=Math.abs(d[0][0]);
			for (int i = 0; i < d.length; i++) {
				for (int j = 0; j < d[0].length; j++) {
					if (Math.abs(d[i][j])<min) {
						min=Math.abs(d[i][j]);
					}
				}
			}
			return min;
		} catch (Exception e) {
			// TODO: handle exception
			return 0;
		}
	}

	private float getMaxConnection(float[][] d) {
		try {
			float max=Math.abs(d[0][0]);
			for (int i = 0; i < d.length; i++) {
				for (int j = 0; j < d[0].length; j++) {
					if (Math.abs(d[i][j])>max) {
						max=Math.abs(d[i][j]);
					}
				}
			}
			return max;
		} catch (Exception e) {
			// TODO: handle exception
			return 0;
		}
	}

//	private double getMinWeight(ArrayList<Node> act) {
//		double min=act.get(0).totalWeight;
//		for (int i = 0; i < act.size(); i++) {
//			if (min>act.get(i).totalWeight) {
//				min=act.get(i).totalWeight;
//			}
//		}
//		return min;
//	}

//	private double getMaxWeight(ArrayList<Node> act) {
//		double max=act.get(0).totalWeight;
//		for (int i = 0; i < act.size(); i++) {
//			if (max<act.get(i).totalWeight) {
//				max=act.get(i).totalWeight;
//			}
//		}
//		return max;
//	}

//	private Point getXYPos(int yer, int img_w, int img_h) {
//		int x=yer/img_h;
//		int y=yer%img_h;
//		Point ret=new Point(x,y);
//		return ret;
//	}

	/**
	 * @return the nn structure
	 */
	public TNeuralNetworkStructure getNNStructure() {
		return nn;
	}

	/**
	 * @param nn the nn to set
	 */
	public void setNNStructure(TNeuralNetworkStructure nn) {
		this.updateInputLayer=0;
		this.nn = nn;
	}

	public void setInputWeightedSumNodes(ArrayList<TMLPNode> _inputWeightedNodes) {
		this.updateInputLayer=1;
		if (inputWeightedNodes==null || _inputWeightedNodes.size()!=inputWeightedNodes.size()) {
			inputWeightedNodes=_inputWeightedNodes;
		}
		ArrayList<TMLPNode> temp=getInputActiveNodes(_inputWeightedNodes);
		if (temp.size()>0) {
			activeInputNodes=temp;
		}
		this.inputWeightedNodes=_inputWeightedNodes;
		repaint();
	}

	public void setHiddenWeightedSumNodes(ArrayList<TMLPNode> _hiddenWeightedNodes) {
		this.updateInputLayer=1;
		if (hiddenWeightedNodes==null || _hiddenWeightedNodes.size()!=hiddenWeightedNodes.size()) {
			hiddenWeightedNodes=_hiddenWeightedNodes;
		}
		ArrayList<TMLPNode> temp=getHiddenActiveNodes(_hiddenWeightedNodes);
		if (temp.size()>0) {
			activeHiddenNodes=temp;
		}
		this.hiddenWeightedNodes=_hiddenWeightedNodes;
		repaint();
	}

	public ArrayList<TMLPNode> getInputActiveNodes(ArrayList<TMLPNode> prm) {
		ArrayList<TMLPNode> retNodes=new ArrayList<TMLPNode>();
		for (int i = 0; i < prm.size(); i++) {
			float w1=prm.get(i).totalWeight;
			float w2=inputWeightedNodes.get(i).totalWeight;
			if (w1!=w2) {
				TMLPNode node=new TMLPNode();
				node.classLabel=prm.get(i).classLabel;
				node.pos=prm.get(i).pos;
				//node.totalWeight=Math.abs(w1-w2);
				node.totalWeight=Math.abs(w1);
				retNodes.add(node);
			}
		}
		if (isRankingFeatures) {
			GenericLib.sortArrayList(1,retNodes);
		}
		return retNodes;
	}
	
	public ArrayList<TMLPNode> getHiddenActiveNodes(ArrayList<TMLPNode> prm) {
		ArrayList<TMLPNode> retNodes=new ArrayList<TMLPNode>();
		for (int i = 0; i < prm.size(); i++) {
			float w1=prm.get(i).totalWeight;
			float w2=hiddenWeightedNodes.get(i).totalWeight;
			if (w1!=w2) {
				TMLPNode node=new TMLPNode();
				node.classLabel=prm.get(i).classLabel;
				node.pos=prm.get(i).pos;
				//node.totalWeight=Math.abs(w1-w2);
				node.totalWeight=Math.abs(w1);
				retNodes.add(node);
			}
		}
		if (isRankingFeatures) {
//			GenericLib.sortArrayList(1,retNodes);
		}
		return retNodes;
	}

	public void setImage(Image img){
		this.img=img;
	}
	
	public Image getImage(){
		return this.img;
	}
}

//onceki surumlerde matris seklinde quantize edilen hucreleri cizen kod blogu
//int im_w=320;
//	int im_h=200;
//	int im_x=340;
//	int im_y=220;
//if (img!=null || img==null) {
//	g.setColor(Color.red);
//	g.drawImage(img,im_x,im_y,im_w,im_h,this);	
//		g.drawRect(im_x,im_y,im_w,im_h);
//	g.drawRect(im_x-1,im_y-1,im_w+2,im_h+2);
//	g.setColor(Color.black);
//	g.fillRect(im_x-1,im_y-1,im_w+2,im_h+2);
//	//int img_w=img.getWidth(null);
//	//int img_h=img.getHeight(null);
//	int img_w=32;
//	int img_h=25;
//	int img_size=img_w*img_h;
//	int pixelWidth=im_w/img_w;
//	int pixelHeight=im_h/img_h;
//	
//	g.setColor(Color.black);
//	g.drawString(img_w+"X"+img_h+" image size:"+img_size, im_x,im_y-10);
//	g.drawString(nn.currentFile, im_x,im_y-30);
//	String str="";  
//	//double max=getMaxWeight(activeNodes);
//	//double min=getMinWeight(activeNodes);
//	double max=activeNodes.get(0).totalWeight;
//	double min=activeNodes.get(activeNodes.size()-1).totalWeight;
//	double delta=Math.abs(max-min);
//	double k=255.0/delta;
//	//projected value color=(xi-min)*k;
//	Color cl=null;
//	for (int i = 0; i < activeNodes.size(); i++) {
//		g.setColor(Color.black);
//		String weight=activeNodes.get(i).totalWeight+"";
//		int yer=activeNodes.get(i).pos;
//		str=i+".active node:"+yer;
//		g.drawString(str, im_x,(im_h+im_y+20)+15*i);
//		Point pnt=getXYPos(yer,img_w,img_h);
//		str="Pos:"+pnt.x+";"+pnt.y;
//			g.drawString(str, im_x+150,(im_h+im_y+20)+15*i);
//		str="W:"+weight;
//		g.drawString(str, im_x+250,(im_h+im_y+20)+15*i);
////		if (i<=50) {
////			g.setColor(Color.green);
////		}
////		if (i>50&&i<=100) {
////			g.setColor(Color.orange);
////		}
////		if (i>100&&i<=150) {
////			g.setColor(Color.yellow);
////		}
////		if (i>150&&i<=200) {
////			g.setColor(Color.red);
////		}
////		if (i>200&&i<=250) {
////			g.setColor(Color.LIGHT_GRAY);
////		}
//		//g.drawRect(im_x+pixelWidth*pnt.x, im_y+pixelHeight*pnt.y,pixelWidth,pixelHeight);
//		int c=Math.abs(Math.round((float)(k*(activeNodes.get(i).totalWeight-min))));
////		System.out.println(i+".color value:"+c);
//		try {
//			cl=new Color(c,c,c);
//			g.setColor(cl);
//		} catch (Exception e) {
//			// TODO: handle exception
//		}
//		g.fillRect(im_x+pixelWidth*pnt.x, im_y+pixelHeight*pnt.y,pixelWidth,pixelHeight);
//	}
//}else{
//	String str="";    		
//	for (int i = 0; i < activeNodes.size(); i++) {
//		g.setColor(Color.DARK_GRAY);
//		String weight=activeNodes.get(i).totalWeight+"";
//		int yer=activeNodes.get(i).pos;
//		str=i+".active node:"+yer;
//		g.drawString(str, im_x,(im_h+20)+15*i);
//		str="W:"+weight;
//		g.drawString(str, im_x+150,(im_h+20)+15*i);
//	}
//}



